#include <cstdio>
#include <cctype>

using namespace std;

#define MAX_LINES 100
#define MAX_CHARS 100
#define LCHAR ('A')
#define RCHAR ('Z' + 1)

#define loop(i,n) for (i = 0; i < n; ++i)


/*********************************************************/


enum POSITION
{
	UNKNOWN = -1,
	NO_TOP,
	TOP
};


struct COORD
{
	int x, y;

	inline void set (int x, int y) {
		this->x = x;
		this->y = y;
	}
};


/*********************************************************/


struct State;

#define ST(f) int f (State *s, int l, int c)
typedef ST((*StateFunction));

ST(start);
ST(first_line);
ST(next_lines);
ST(last_line);


struct State
{
	POSITION position;
	StateFunction function;
	COORD first, last;
	bool right_side;

	void reset () {
		position = UNKNOWN;
		function = start;
		right_side = false;
	}

	void check (int l, int c) {
		while (position == UNKNOWN && function (this, l, c));
	}
};


/*********************************************************/


ST (start)
{
	s->first.set (l, c);
	s->last.set (l, c);
	s->function = first_line;
	return 0;
}


ST (first_line)
{
	if (l > s->first.x) {
		if (s->last.y - s->first.y < 2) {
			s->position = NO_TOP;
			return 0;
		}
		s->last.x = s->first.x;
		s->function = next_lines;
		return 1;
	}
	if (c - s->last.y != 1) {
		s->position = NO_TOP;
		return 0;
	}
	s->last.y = c;
	return 0;
}


ST (next_lines)
{
	switch (l - s->last.x)
	{
		case 0:
		{
			if (c - s->first.y == 1) {
				s->function = last_line;
				return 1;
			}
			if (c != s->last.y) {
				s->position = NO_TOP;
				return 0;
			}
			s->right_side ^= 1;
			break;
		}

		case 1:
		{
			if (s->right_side) {
				s->position = NO_TOP;
				return 0;
			}
			if (c != s->first.y) {
				s->position = NO_TOP;
				return 0;
			}
			s->last.x = l;
			s->right_side ^= 1;
			break;
		}

		default:
		{
			s->position = NO_TOP;
			return 0;
		}
	}

	return 0;
}


ST (last_line)
{
	if (c - s->first.y != 1) {
		s->position = NO_TOP;
		return 0;
	}
	if (c == s->last.y) {
		s->position = TOP;
		return 0;
	}
	s->first.y = c;
	return 0;
}


/*********************************************************/


int main ()
{
	int lines, chars, l, c, w;
	State window[RCHAR];

	while (scanf ("%d %d\n", &lines, &chars), lines)
	{
		for (w = LCHAR; w < RCHAR; ++w)
			window[w].reset();

		loop (l, lines)
		{
			loop (c, chars)
			{
				w = getchar();
				if (isupper(w))
					window[w].check (l, c);
			}

			getchar();
		}

		for (w = LCHAR; w < RCHAR; ++w)
		{
			if (window[w].position == TOP)
				putchar(w);
		}
		putchar('\n');
	}

	return 0;
}